<style lang="less">
  .fileNameDiv {
    max-height: 44px;
    height: 44px;
    overflow : hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .text-overflow{
    overflow: hidden;
    -webkit-line-clamp: 2;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    margin-top:6px;
  }
  .ivu-tooltip-content {
    width: max-content;
  }
  .ivu-tooltip-popper ivu-tooltip-dark {
    width: max-content;
    position: absolute;
    will-change: top, left;
    top: -47px;
    left: -58px;
    display: none;
  }
  .card_style {
    height: 100%;
    width: 100%;
    overflow: hidden;
    .ivu-card-body {
      padding: 0px;
    }
  }
  .page_style {
    margin-top: 10px;
    text-align: right;
  }
  .bench_search {
    margin-bottom: 10px;
  }
  .nopadding .ivu-table-cell {
    padding: 0px 0px;
  }
  .item1{
    height: 42px;
    line-height: 40px;
  }
  .new-btn-sty {
    margin-right: 5px;
    color: #fff;
    background-color: #235CA7;
    border-color: #235CA7;
    font-weight: 500;
  }
</style>

<template>
  <Card class="card_style" :bordered="false" :dis-hover="true">
    <Row class="bench_search">
      <Col span="6" offset="1">
        <span>标题：</span>
        <Input style="width: 70%;" v-model="searchInfo.title" />
      </Col>
      <Col span="5" v-if="companyCode === 'LM'">
        <span>状态：</span>
        <Select v-model="searchInfo.state" style="width: 75%;">
          <Option value="">全部</Option>
          <Option value="0">未发布</Option>
          <Option value="1">发布中</Option>
        </Select>
      </Col>
      <Button class="new-btn-sty" @click="searchData" style="margin-right:10px"><Icon type="ios-search" /> 搜索</Button>
      <Button class="new-btn-sty" @click="editNotice({})" v-if="companyCode === 'LM'"><Icon type="md-add" /> 创建</Button>
      <Modal v-model="modalEdit" title="通知基本信息" width="700" cancel-text="关闭"
        @on-ok="ok111(paramData2)" @on-cancel="modalEdit=false" ok-text="确定">
        <Form :model="paramData2" >
          <Row class="item1">
            <Col span="5" style="text-align: right" class="">标题:</Col>
            <Col span="12" offset="1">
              <Input v-model="paramData2.title"></Input>
            </Col>
          </Row>
          <Row class="item1" style="height:auto;">
            <Col span="5" style="text-align: right" class="">内容:</Col>
            <Col span="12" offset="1">
              <Input v-model="paramData2.content" type="textarea" :autosize="{minRows: 2,maxRows: 5}"></Input>
            </Col>
          </Row>
          <Row class="item1">
            <Col span="5" style="text-align: right" class="">排序:</Col>
            <Col span="12" offset="1">
              <Input v-model="paramData2.sort"></Input>
            </Col>
          </Row>
          <Row class="item1">
            <Col span="5" style="text-align: right" class="">文件:</Col>
            <Col span="3" offset="1">
              <Button type="primary" @click="uploadFile">上传文件</Button>
            </Col>
          </Row>
          <Row class="item1" style="height:auto;line-height:20px;margin-top: 10px;padding-left:20%">
            <Col span="4" offset="1" v-for="(item, index) in fileArr" v-bind:key="index" style="margin-top:10px">
              <div>
                <Tooltip max-width="800"  :content="item.file_name" placement="top" style="margin-left:30%">
                  <i class='iconfont icon-pdf' style="font-size:30px;color:red;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.pdf') != -1 || (item.file_url).indexOf('.PDF') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-tupian' style="font-size:30px;color:orange;margin-right:50px;cursor: pointer;" v-if="item.file_url.indexOf('.jpg') != -1 || item.file_url.indexOf('.JPG') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-tupian' style="font-size:30px;color:orange;margin-right:50px;cursor: pointer;" v-if="item.file_url.indexOf('.png') != -1 || item.file_url.indexOf('.PNG') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-tupian' style="font-size:30px;color:orange;margin-right:50px;cursor: pointer;" v-if="item.file_url.indexOf('.jpeg') != -1 || item.file_url.indexOf('.JPEG') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-WORD' style="font-size:30px;color:blue;margin-right:50px;cursor: pointer;" v-if="item.file_url.indexOf('.doc') != -1 || item.file_url.indexOf('.DOC') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-excel1' style="font-size:30px;color:green;margin-right:50px;cursor: pointer;" v-if="item.file_url.indexOf('.xls') != -1 || item.file_url.indexOf('.XLS') != -1" @click="openFile(item.file_url)"></i>
                </Tooltip>
                <div class="fileNameDiv">{{item.file_name}}</div>
              </div>
            </Col>
          </Row>
        </Form>
      </Modal>
      <Modal v-model="up_pic_mol" title="文件上传" @on-ok="changeToView" :closable="false">
        <Upload multiple action="http://120.27.63.37:38081/api/ac/file/fileCommonService/upLoadFiles" :before-upload="beforeUpload">
          <Button icon="ios-cloud-upload-outline">上传文件</Button>
          <span style="margin-left: 250px">请上传小于8M的文件</span>
        </Upload>
        <img :src="temp_photo" style="width: 100%"/>
      </Modal>
      <Modal v-model="showItemNotice" title="配置事项" @on-ok="addItemNotice">
        <Tree :data="itemData" show-checkbox @on-check-change="itemOnChange"></Tree>
        <Row>
          <Col span="3" style="line-height: 2.5">失效时间:</Col>
          <Col span="18">
            <DatePicker type="datetime" placeholder="选择失效时间" v-model="invalid_time"></DatePicker>
          </Col>
        </Row>
      </Modal>
      <Modal v-model="showNotice" title="通知详情" width="700">
        <Form :model="paramData">
          <Row class="item1">
            <Col span="6" style="text-align: right" class="red-name">标题:</Col>
            <Col span="12" offset="1">{{paramData.title}}</Col>
          </Row>
          <Row class="item1" style="height:auto;">
            <Col span="6" style="text-align: right" class="">内容:</Col>
            <Col span="12" offset="1">{{paramData.content}}</Col>
          </Row>
          <Row class="item1">
            <Col span="6" style="text-align: right" class="">排序:</Col>
            <Col span="12" offset="1">{{paramData.sort}}</Col>
          </Row>
          <Row class="item1">
            <Col span="6" style="text-align: right" class="">文件:</Col>
          </Row>
          <Row class="item1" style="height:auto;line-height:20px;margin-top: 10px;padding-left:20%">
            <Col span="4" v-for="(item, index) in fileArr" v-bind:key="index" style="margin-top:10px;">
              <div>
                <Tooltip max-width="800" :content="item.file_name" placement="top" style="margin-left:30%;width: max-content;">
                  <i class='iconfont icon-pdf' style="font-size:30px;color:red;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.pdf') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-tupian' style="font-size:30px;color:orange;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.jpg') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-tupian' style="font-size:30px;color:orange;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.png') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-tupian' style="font-size:30px;color:orange;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.jpeg') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-WORD' style="font-size:30px;color:blue;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.doc') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-excel1' style="font-size:30px;color:green;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.xls') != -1" @click="openFile(item.file_url)"></i>
                </Tooltip>
                <div class="fileNameDiv">{{item.file_name}}</div>
              </div>
            </Col>
          </Row>
          <Row class="item1">
            <Col span="6" style="text-align: right" class="red-name">发布时间:</Col>
            <Col span="12" offset="1">{{paramData.release_time}}</Col>
          </Row>
        </Form>
        <div slot="footer">
          <Button type="error" @click="showNotice=false">关闭</Button>
        </div>
      </Modal>
    </Row>
    <Table border v-if="companyCode == 'LM'" :columns="columns1" :data="datalist"></Table>
    <Table border v-if="companyCode != 'LM'" :columns="columns2" :data="datalist">
      <template slot-scope="{ row }" slot="title">
        <Tooltip max-width="400" transfer data-container="body" :content="row.title" placement="top">
          <div class="text-overflow">{{row.title}}</div>
        </Tooltip>
      </template>
      <template slot-scope="{ row }" slot="content">
        <Tooltip max-width="400" transfer data-container="body" :content="row.content" placement="top">
          <div class="text-overflow">{{row.content}}</div>
        </Tooltip>
      </template>
      <template slot-scope="{ row }" slot="file_url">
        <Dropdown transfer v-if="row.file_url">
          <Button type="primary">
            附件
            <Icon type="ios-arrow-down"></Icon>
          </Button>
          <DropdownMenu slot="list">
              <DropdownItem v-for="(item, index) in (row.file_url ? row.file_url : []) " v-bind:key="index">
                <Tooltip transfer max-width="300" :content="item.file_name" placement="right" style="margin-left:30%;width: max-content;">
                  <i class='iconfont icon-pdf' style="font-size:30px;color:red;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.pdf') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-tupian' style="font-size:30px;color:orange;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.jpg') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-tupian' style="font-size:30px;color:orange;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.png') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-tupian' style="font-size:30px;color:orange;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.jpeg') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-WORD' style="font-size:30px;color:blue;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.doc') != -1" @click="openFile(item.file_url)"></i>
                  <i class='iconfont icon-excel1' style="font-size:30px;color:green;margin-right:50px;cursor: pointer;" v-if="(item.file_url).indexOf('.xls') != -1" @click="openFile(item.file_url)"></i>
                </Tooltip>
              </DropdownItem>
          </DropdownMenu>
        </Dropdown>
      </template>
    </Table>
    <Row v-if="loadData == true">
      <Col class="demo-spin-col" span="8" offset="8">
        <Spin fix>
          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
          <div>数据正在加载</div>
        </Spin>
      </Col>
    </Row>
    <!-- <Page :total="totalnum" :current="currentPageNo" :page-size="currentPageSize" @on-change="change" class="page_style"/> -->
  </Card>
</template>

<script>
import {
  noticeList,
  saveNotice,
  setReleaseState,
  deleteNotice,
  datetime2str,
  setReleaseStress,
  getItemNoticeTreeList,
  addItemNotice, date0str
} from '@/api/eventlist'
import { releaseNoticeList } from '@/api/mainv3'
import { getSign, createUpLoadFiles } from '@/api/common'
import * as imageConversion from 'image-conversion'
// import OldAgeAllowance
//   from '../../../../.history/src/view/xian-page/handinformation/components/oldAgeAllowance/index_20201130154112'
import MenuOption from '../../../components/system/wl-menu-manager/components/menu-option'
export default {
  name: 'message',
  components: { MenuOption },
  data () {
    return {
      notice_id: '',
      invalid_time: '',
      itemData: [],
      showItemNotice: false,
      temp_photo: '',
      upPicData: {},
      up_pic_mol: false,
      loadData: true,
      showNotice: false,
      modalEdit: false,
      params: { pageNo: '', pageSize: '' },
      searchInfo: { title: '', state: '' },
      paramData: {},
      // 修改或添加新通知公告时使用
      paramData2: {},
      totalnum: 0,
      columns1: [
        { title: '序号', type: 'index', width: 70, align: 'center' },
        { title: '标题', key: 'title', width: 300, align: 'center' },
        {
          title: '状态',
          key: 'state',
          width: 150,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.state === '1' ? '发布中' : '未发布')
          }
        },
        {
          title: '公告类型',
          key: 'stress',
          width: 150,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.stress === '1' ? '重点公告' : '普通公告')
          }
        },
        // { title: '公告类型', key: 'stressname', width: 250, align: 'center' },
        { title: '创建时间', key: 'create_time', width: 200, align: 'center' },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          className: 'nopadding',
          minWidth: 100,
          render: (h, params) => {
            let temp = []
            if (this.companyCode === 'LM') {
              temp.push(
                h('Button', {
                  props: { type: 'primary', size: 'small' },
                  style: { marginRight: '5px', backgroundColor: '#598ED1', borderColor: '#598ED1' },
                  on: {
                    click: () => {
                      this.editNotice(params.row)
                    }
                  }
                }, '编辑'),
                h('Button', {
                  props: { type: 'info', size: 'small' },
                  style: { marginRight: '5px', backgroundColor: '#235CA7', borderColor: '#235CA7' },
                  on: {
                    click: () => {
                      this.showInfo(params.row)
                    }
                  }
                }, '详情'),
                h('Button', {
                  props: { type: 'error', size: 'small' },
                  style: { marginRight: '5px' },
                  on: {
                    click: () => {
                      this.remove(params.row)
                    }
                  }
                }, '删除')
              )
              if (params.row.state === '0') {
                temp.push(
                  h('Button', {
                    props: { type: 'success', size: 'small' },
                    style: { marginRight: '5px' },
                    on: {
                      click: () => {
                        this.setNoticeState(params.row, '1')
                      }
                    }
                  }, '发布')
                )
              }
              if (params.row.state === '1') {
                temp.push([
                  h('Button', {
                    props: { type: 'primary', size: 'small' },
                    style: { marginRight: '5px', backgroundColor: '#598ED1', borderColor: '#598ED1' },
                    on: {
                      click: () => {
                        this.editItemNotice(params.row)
                      }
                    }
                  }, '配置事项'),
                  h('Button', {
                    props: { type: 'warning', size: 'small' },
                    style: { marginRight: '5px' },
                    on: {
                      click: () => {
                        this.setNoticeState(params.row, '0')
                      }
                    }
                  }, '撤销')
                ])
              }
              if (params.row.stress === '0') {
                temp.push(
                  h('Button', {
                    props: { type: 'info', size: 'small' },
                    style: { marginRight: '5px' },
                    on: {
                      click: () => {
                        this.setNoticeStress(params.row, '1')
                      }
                    }
                  }, '重点公告')
                )
              }
              if (params.row.stress === '1') {
                temp.push([
                  h('Button', {
                    props: { type: 'success', size: 'small' },
                    // style: { marginRight: '5px', backgroundColor: '#598ED1', borderColor: '#598ED1' },
                    on: {
                      click: () => {
                        this.setNoticeStress(params.row, '0')
                      }
                    }
                  }, '普通公告')
                ])
              }
            } else {
              temp.push(
                h('Button', {
                  props: { type: 'primary', size: 'small' },
                  // style: { marginRight: '5px', backgroundColor: '#598ED1', borderColor: '#598ED1' },
                  on: {
                    click: () => {
                      this.showInfo(params.row)
                    }
                  }
                }, '详情')
              )
            }
            return h('div', temp)
          }
        }
      ],
      columns2: [
        { title: '序号', type: 'index', width: 70, align: 'center' },
        { title: '标题', slot: 'title', width: 320, align: 'center' },
        { title: '内容', slot: 'content', width: 420, align: 'center' },
        {
          title: '公告类型',
          key: 'stress',
          width: 200,
          align: 'center',
          render: (h, params) => {
            return h('span', params.row.stress === '1' ? '重点公告' : '普通公告')
          }
        },
        { title: '发布时间', key: 'release_time', width: 200, align: 'center' },
        { title: '附件', slot: 'file_url', width: 200, align: 'center' }
      ],
      datalist: [],
      fileArr: [],
      itemList: []
    }
  },
  computed: {
    companyCode () {
      return this.$store.state.user.severUserInfo.company_code
    }
  },
  methods: {
    addItemNotice () {
      let params = {
        notice_id: this.notice_id,
        invalid_time: date0str(this.invalid_time),
        item_List: this.itemList
      }
      console.log(params, 'lllll')
      addItemNotice(params).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '成功', desc: res.data.data.num })
        } else {
          this.$Notice.error({ title: '失败', desc: res.data.errmsg })
        }
      })
    },
    itemOnChange (param1, param2) {
      let param = JSON.parse(JSON.stringify(param1))
      console.log(param, 'paramdddddd')
      for (var i = 0; i < param.length; i++) {
        if (param[i].hasOwnProperty('children')) {
          param.splice(i, 1)
          i--
        }
      }
      this.itemList = param
      console.log(param, 'paramffff')
      console.log(param1, 'param1')
      console.log(param2, 'param2')
    },
    editItemNotice (param) {
      getItemNoticeTreeList(param).then(res => {
        if (res.data.errcode === 0) {
          this.itemData = res.data.data.list
          this.notice_id = param.id
          this.invalid_time = res.data.data.invalid_time
          // let render = { render: (h, { root, node, data }) => {
          //   let temp = []
          //   temp.push(
          //     h('span', {
          //       style: {
          //       }
          //     }, data.title),
          //     h('DatePicker', {
          //       props: {
          //         value: data.time,
          //         type: 'datetime'
          //       },
          //       style: {
          //         // display: 'inline-block',
          //         width: '200px',
          //         height: '10%',
          //         'margin-left': '20px'
          //       },
          //       on: {
          //         'on-change': (event) => {
          //           console.log(event, 'lllllllll')
          //         }
          //       }
          //     })
          //   )
          //   return h('div', temp)
          // } }
          // this.itemData.forEach(temp => {
          //   temp = Object.assign(temp, render)
          // })
          // console.log(this.itemData)
        } else {
          this.$Notice.error({ title: '事项获取失败', desc: res.data.errmsg })
        }
      })
      this.showItemNotice = true
    },
    // 查询订单列表接口
    init (param) {
      if (this.companyCode === 'LM') {
        noticeList(param).then(res => {
          if (res.data.errcode === 0) {
            this.datalist = res.data.data
            this.loadData = false
          } else {
            this.loadData = true
            this.$Notice.error({ title: '获取通知公告列表失败', desc: res.data.errmsg })
          }
        })
      } else {
        releaseNoticeList(param).then(res => {
          if (res.data.errcode === 0) {
            this.datalist = res.data.data
            this.loadData = false
            this.datalist.forEach(param => {
              if (param.file_url) {
                param.file_url = JSON.parse(param.file_url)
              }
            })
          } else {
            this.loadData = true
            this.$Notice.error({ title: '获取通知公告列表失败', desc: res.data.errmsg })
          }
        })
      }
    },
    ok111 (param) {
      saveNotice(param).then(res => {
        if (res.data.errcode === 0) {
          this.init(this.params)
          this.$Notice.success({ title: '成功', desc: '' })
        } else {
          this.$Notice.error({ title: '失败', desc: res.data.errmsg })
        }
      })
    },
    showInfo (item) {
      this.paramData2 = {}
      this.fileArr = []
      this.showNotice = true
      this.paramData.title = item.title
      this.paramData.content = item.content
      this.paramData.sort = item.sort
      this.paramData.release_time = item.release_time
      if (item.file_url) {
        this.fileArr = JSON.parse(item.file_url)
      }
    },
    editNotice (item) {
      console.log('edit')
      this.paramData2 = {}
      this.fileArr = []
      this.modalEdit = true
      this.paramData2.id = item.id || null
      this.paramData2.title = item.title || ''
      this.paramData2.content = item.content || ''
      this.paramData2.sort = item.sort || ''
      if (item.file_url) {
        this.fileArr = JSON.parse(item.file_url)
      }
    },
    remove (item) {
      if (confirm('确定删除该条数据吗')) {
        deleteNotice({ id: item.id }).then(res => {
          if (res.data.errcode === 0) {
            this.init(this.params)
            return
          }
          this.$Notice.error({ title: '删除失败', desc: res.errmsg })
        })
      }
    },
    searchData () {
      let params = {
        state: this.searchInfo.state,
        title: this.searchInfo.title
      }
      this.currentPageNo = 1
      this.init(params)
    },
    change (pageNo) {
      this.currentPageNo = pageNo
      let params = {
        state: this.searchInfo.state,
        title: this.searchInfo.title
      }
      this.init(params)
    },
    // 发布or撤销,state==='1'时表示发布通知，state==='0'时表示撤销通知
    setNoticeState (item, state) {
      let msg = state === '1' ? '确定发布此通知吗！' : '确认撤销此通知吗！'
      var param = { id: item.id, state: state }
      if (confirm(msg)) {
        setReleaseState(param).then(res => {
          if (res.data.errcode === 0) {
            this.init(this.params)
            return
          }
          this.$Notice.error({ title: '失败', desc: res.errmsg })
        })
      }
    },
    // 发布or撤销,state==='1'时表示发布通知，state==='0'时表示撤销通知
    setNoticeStress (item, stress) {
      let msg = stress === '1' ? '确定修改为重点通知吗！' : '确定修改为普通通知吗！'
      var param = { id: item.id, stress: stress }
      if (confirm(msg)) {
        setReleaseStress(param).then(res => {
          if (res.data.errcode === 0) {
            this.init(this.params)
            return
          }
          this.$Notice.error({ title: '失败', desc: res.errmsg })
        })
      }
    },
    uploadFile () {
      this.up_pic_mol = true
    },
    openFile (url) {
      window.open(url)
    },
    // 上传图片前转base64
    beforeUpload (file) {
      console.log(file.size / 1024 / 1024, '大小')
      // var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      // if (file.size / 1024 / 1024 > 1) { // 超过1M 压缩 图片为200K
      //   return this.beforeAvatarUpload(file)
      // }
      // const isLt2M = file.size / 1024 / 1024 < 8
      // if (!isLt2M) {
      //   this.$Notice.error({ title: '上传失败', desc: '请上传图片小于8M的文件' })
      //   return
      // }
      console.log(file, 'filelelelle')
      // return isLt2M
      this.upPicData.fileName = datetime2str(new Date()) + file.name
      this.upPicData.file_name = file.name
      this.upPicData.filePath = 'message/' + datetime2str(new Date())
      let that = this
      const reader = new FileReader()
      reader.readAsDataURL(file)
      reader.onload = () => {
        let index = reader.result.indexOf('base64,') + 7
        that.upPicData.file = reader.result.substring(index)
        that.upPic(that.upPicData)
      }
      return false
    },
    // 把图片文件作为参数传递到方法中进行压缩
    beforeAvatarUpload (file) {
      console.log(file, '#￥@￥#@￥@#')
      const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/jpg'
      if (!isJpgOrPng) {
        this.$Notice.error({ title: '上传失败', desc: '上传图片只能是 JPG 或 PNG、JPEG 格式!' })
        return false
      }
      return new Promise(() => {
        imageConversion.compressAccurately(file, 400).then(res => {
          let that = this
          const reader = new FileReader()
          reader.readAsDataURL(new File([res], '', { type: res.type, lastModified: Date.now() }))
          that.upPicData.fileName = datetime2str(new Date()) + file.name
          this.upPicData.file_name = file.name
          that.upPicData.filePath = 'message/' + datetime2str(new Date())
          reader.onload = () => {
            console.log('^^^^^^')
            let index = reader.result.indexOf('base64,') + 7
            // that.upPicData.fileName = this.upPicData.fileName + '.' + file.type.substring(6)
            that.upPicData.file = reader.result.substring(index)
            that.upPic(that.upPicData)
          }
        })
      })
    },
    // 上传图片
    upPic (obj) {
      var time = new Date().getTime()
      this.timeStep = time.toString()
      let param = {
        filePath: obj.filePath,
        fileName: obj.fileName,
        timestamp: this.timeStep
      }
      getSign(param).then(res => {
        if (res.data.errcode === 0) {
          createUpLoadFiles(res.data.data.docking_url, { sign: res.data.data.sign, timestamp: this.timeStep, filePath: param.filePath, fileName: param.fileName, file: obj.file }).then(res => {
            if (res.data.errcode === 0) {
              console.log('上传成功')
              this.up_pic_mol = false
              var fileData = {
                file_name: obj.file_name,
                file_url: res.data.data
              }
              console.log(fileData, 'fileData')
              this.fileArr.push(fileData)
              console.log(this.fileArr)
              this.paramData2.file_url = JSON.stringify(this.fileArr)
              console.log(this.paramData2)
              console.log(this.paramData2.file_url)
              // let imgurl = res.data.data
              // let list = this.documentlist[this.formItem.paramIndex]
              // if (list.img_urls) {
              //   list.img_urls.push(imgurl)
              // } else {
              //   list.img_urls = [imgurl]
              // }
              // this.temp_photo = imgurl
              // console.log(this.formItem.operation)
            } else {
              this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
            }
          })
        } else {
          this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
        }
      })
    },
    changeToView () {
      // this.formItem.reloadTabel = true
      // let temp = this.documentlist[this.formItem.paramIndex]
      // if (temp.img_urls || temp.write_type === 'form') {
      //   temp.is_submit = '已提交'
      // }
      // this.$nextTick(() => {
      //   this.formItem.reloadTabel = false
      // })
    }
  },
  mounted () {
    this.init(this.params)
  }
}
</script>
